<?php

/**
 * Description of Order
 *
 * @author Vu
 */
 
class Order extends Zend_Db_Table_Abstract {
	
	protected $_name = 'cms_order';
    protected $_primary = 'order_id';
    
	public function getAllOrders($page = 1, $order = "a.created desc"){
        $tb = Zend_Db_Table::getDefaultAdapter();
        $tb->setFetchMode(Zend_Db::FETCH_OBJ);
        
        $select = $tb->select()
					->from(array('a' => 'cms_order'))
					->join(array('b' => 'cms_order_type'), "a.order_type_id = b.order_type_id")
					->order($order);
        $paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(Zend_Registry::get('page_size'));
    	$paginator->setCurrentPageNumber($page); 
    	
        return $paginator;
    }
    
	public function getOrderById($orderid){
        return $this->fetchRow($this->select()->where('order_id=?', $orderid));
    }
	
	public function getOrderByInvoiceCode($invoice_code){
        return $this->fetchRow($this->select()->where('invoice_code=?', $invoice_code));
    }
}